package com.chenjt.juc.nine_atomics;

import java.util.concurrent.atomic.LongAccumulator;
import java.util.concurrent.atomic.LongAdder;
import java.util.function.LongBinaryOperator;

/**
 * 注释：
 *
 * @author chenjt
 * @date 2024/7/12 14:19
 */
public class LongAdderAPIDemo {


    public static void main(String[] args) {
        LongAdder longAdder = new LongAdder();

        longAdder.increment();
        longAdder.increment();
        longAdder.increment();

        System.out.println(longAdder.sum());

//        LongAccumulator longAccumulator = new LongAccumulator(new LongBinaryOperator() {
//            @Override
//            public long applyAsLong(long left, long right) {
//                return left + right;
//            }
//        },0);// 0就是x
        LongAccumulator longAccumulator = new LongAccumulator((x, y) -> x + y, 0);// 0就是x
        longAccumulator.accumulate(1);//1就是y  1
        longAccumulator.accumulate(3);//3就是y  4

        System.out.println(longAccumulator.get());


    }


}
